﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Zadanie4
{
    public partial class Form1 : Form
    {
        private Problem problem = new Problem();

        public Form1()
        {
            InitializeComponent();
        }

        private void UpdateHandler()
        {
            try
            {
                this.Invoke((MethodInvoker)delegate
                {
                    this.label1.Text = "Waiting southbound: " + problem.WaitingSouthbound;
                    this.label2.Text = "Passing southbound: " + problem.PassingSouthbound;
                    this.label3.Text = "Passing northbound: " + problem.PassingNorthbound;
                    this.label4.Text = "Waiting northbound: " + problem.WaitingNorthbound;
                });
            }catch
            {
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            problem.Changed += UpdateHandler;
            problem.Run();
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            problem.Stop();
        }
    }
}
